package site.marqstree.elecommerce.app.event;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mob.MobSDK;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import site.marqstree.latte.core.delegates.web.event.Event;
import site.marqstree.latte.core.util.log.LatteLogger;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.elecommerce.app.event
 * 文件名: ShareEvent
 * 创建者: marqstree
 * 创建时间: 2020/2/8 13:19
 * 描述: js调用android原生分享接口
 */
public class ShareEvent extends Event {
    @Override
    public String execute(String params) {
        LatteLogger.json("ShareEvent", params);

        //获取web传入的json
        final JSONObject object = JSON.parseObject(params).getJSONObject("params");
        //微信分享标题
        final String title = object.getString("title");
        //微信分享url
        final String url = object.getString("url");
        //微信分享封面图片
        final String imageUrl = object.getString("imageUrl");
        //微信分享封面内容
        final String text = object.getString("text");

        //底部弹出分享对话框
        //调用Mob分享API
        MobSDK.init(getContext());
        final OnekeyShare oks = new OnekeyShare();
        oks.disableSSOWhenAuthorize();
        oks.setTitle(title);
        oks.setText(text);
        oks.setImageUrl(imageUrl);
        oks.setUrl(url);
        oks.show(getContext());

        return null;
    }
}
